package CommonGui;


import java.awt.Color;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;

import jpos.JposException;
import jpos.POSPrinter;
import jpos.POSPrinterConst;

public class Printer extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel jPanel_Frame;
	private JButton jButton_SamplePrint;
	private JButton jButton_LOGO;
	private JButton jButton_Barcode;
	private JButton jButton_CodePage;
	private JButton jButton_Merchant;
	private JButton jButton_Customer;
	private JButton jButton_PrintReceipt;
	private JButton jButton_ATMReceipt;
	private JButton jButton_AccountSumm;
	private JButton jButton_DirectIOSample;
	private Insets Insets_Button;
	private Border Border_Border;
	private TitledBorder TitledBorder_ReceiptRetail;
	private TitledBorder TitledBorder_ReceiptBanking;
	private TitledBorder TitledBorder_CutMode;
	private Color Color_Border;
	private JPanel jPanel_ReceiptRetail;
	private JPanel jPanel_ReceiptBanking;
	private JPanel jPanel_CutMode;
	private JRadioButton jRadioBTN_PartCut;
	private JRadioButton jRadioBTN_FullCut;
	private JRadioButton jRadioBTN_NoCut;
	private ButtonGroup BTNGroup_CutMode;
	private POSPrinter jPos_Printer;
	private int nCut;

	final int PRN_DI_OUTPUT_NORMAL = 100;

	public static void main(String args[]) {
		(new Printer()).setVisible(true);
	}

	public Dimension getcenter() {
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension frameSize = this.getSize();
		Dimension dim = new Dimension((screenSize.width - frameSize.width) / 2,
				(screenSize.height - frameSize.height) / 2);
		return dim;
	}

	private void exitForm(WindowEvent evt) {
		System.exit(0);
	}

	private String sPace(int iLenth) {
		// TODO Auto-generated method stub
		String sSpace;
		char chSpace[] = new char[iLenth];
		for (int j = 0; j < iLenth; j++) {
			chSpace[j] = (char) 0x20;
		}
		sSpace = new String(chSpace);
		return sSpace;
	}

	private String sLine(int iLenth) {
		String sSpace;
		char chSpace[] = new char[iLenth];
		for (int j = 0; j < iLenth; j++) {
			chSpace[j] = (char) 0x2D;
		}
		sSpace = new String(chSpace);
		return sSpace;
	}

	private void InitFram() {
		jPanel_Frame = new JPanel();
		jPanel_ReceiptRetail = new JPanel();
		jPanel_ReceiptBanking = new JPanel();
		jPanel_CutMode = new JPanel();
		jButton_SamplePrint = new JButton();
		jButton_LOGO = new JButton();
		jButton_Barcode = new JButton();
		jButton_CodePage = new JButton();
		jButton_Merchant = new JButton();
		jButton_Customer = new JButton();
		jButton_PrintReceipt = new JButton();
		jButton_ATMReceipt = new JButton();
		jButton_AccountSumm = new JButton();
		jButton_DirectIOSample = new JButton();
		Insets_Button = new Insets(5, 5, 5, 5);
		Color_Border = new Color(180, 180, 180);
		jRadioBTN_PartCut = new JRadioButton("Part Cut");
		jRadioBTN_FullCut = new JRadioButton("Full Cut");
		jRadioBTN_NoCut = new JRadioButton("No Cut");
		BTNGroup_CutMode = new ButtonGroup();
		jPos_Printer = new POSPrinter();

		setSize(360, 350);
		setLocation(this.getcenter().width, this.getcenter().height);
		getContentPane().add(jPanel_Frame, "Center");
		this.setResizable(false);
		this.setTitle("Sample [Printer]");

		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent evt) {
				exitForm(evt);
			}
		});

		BTNGroup_CutMode.add(jRadioBTN_PartCut);
		BTNGroup_CutMode.add(jRadioBTN_FullCut);
		BTNGroup_CutMode.add(jRadioBTN_NoCut);
		// jRadioBTN_PartCut.setSelected(true);

		Border_Border = BorderFactory.createLineBorder(Color_Border);
		TitledBorder_ReceiptRetail = BorderFactory.createTitledBorder(
				Border_Border, "Receipt-Retail");
		TitledBorder_ReceiptBanking = BorderFactory.createTitledBorder(
				Border_Border, "Receipt-Banking");
		TitledBorder_CutMode = BorderFactory.createTitledBorder(Border_Border,
				"Cut Mode");
		jPanel_ReceiptRetail.setBorder(TitledBorder_ReceiptRetail);
		jPanel_ReceiptBanking.setBorder(TitledBorder_ReceiptBanking);
		jPanel_CutMode.setBorder(TitledBorder_CutMode);

		jPanel_Frame.setLayout(new BoxLayout(jPanel_Frame, 0));
		jPanel_Frame.setMinimumSize(new Dimension(320, 335));
		jPanel_Frame.setPreferredSize(new Dimension(320, 335));

		// jButton_SamplePrint.setAction(AbstractAction);
		jRadioBTN_PartCut.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				nCut = 0;
			}
		});

		jRadioBTN_FullCut.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				nCut = 1;
			}
		});

		jRadioBTN_NoCut.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				nCut = 2;
			}
		});

		jButton_SamplePrint.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				String ESC = ((char) 0x1b) + "";
				String sBuf = "";

				try {
					jPos_Printer.getCapRecPresent();
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"This Printer doesn't have the Receipt Station.",
							"Printer", 0);
					return;
				}

				try {
					jPos_Printer.transactionPrint(
							POSPrinterConst.PTR_S_RECEIPT,
							POSPrinterConst.PTR_TP_TRANSACTION);
				} catch (JposException e1) {
					e1.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"Can't use a POS Printer.", "Printer", 0);
					return;
				}

				try {
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|cA" + ESC + "|2C" + "BTP-R880NP\n");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|500uF");// if MapMode is set to
					// PTR_MM_METRIC,then Feed the paper 5
					// millimeter (500*0.01 millimeter = 5
					// millimeter)
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|cA" + ESC + "|2C" + "POS Thermal Printer\n");// Aligns
					// the
					// text
					// in
					// the
					// center
					// and
					// Prints
					// text
					// in
					// double-wide
					// characters.
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|800uF");// if MapMode is set to
					// PTR_MM_METRIC,then Feed the paper 8
					// millimeter (800*0.01 millimeter = 8
					// millimeter)
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|cA" + "Easy to load\n");// Aligns the text in
					// the center.
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|cA" + "Easy to use\n");// Aligns the text in the
					// center.
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|800uF");// if MapMode is set to
					// PTR_MM_METRIC,then Feed the paper 8
					// millimeter (800*0.01 millimeter = 8
					// millimeter)
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|rA" + "The Leader for Printer Solution\n");// Aligns
					// the
					// text
					// at
					// the
					// right.
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|500uF");// if MapMode is set to
					// PTR_MM_METRIC,then Feed the paper 5
					// millimeter (500*0.01 millimeter = 5
					// millimeter)
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|cA" + ESC + "|2vC" + "Double High\n");// Aligns
					// the
					// text
					// in
					// the
					// center
					// and
					// prints
					// with
					// the
					// height
					// scaled
					// 2
					// times
					// the
					// normal
					// size
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|cA" + ESC + "|2hC" + "Double Wide\n");// Aligns
					// the
					// text
					// in
					// the
					// center
					// and
					// prints
					// with
					// the
					// width
					// scaled
					// 2
					// times
					// the
					// normal
					// size,
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|4C" + "Double High and Wide\n");// Prints
					// double-high
					// and
					// double-wide
					// characters.
				} catch (JposException e1) {
					e1.printStackTrace();
				}

				try {
					sBuf = String.format("|%dlF", jPos_Printer
							.getRecLinesToPaperCut());
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}

				try {
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ sBuf);
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}

				try {
					boolean blResult = jPos_Printer.getCapRecPapercut();
					if (blResult == true) {
						switch (nCut) {
						case 0:
							jPos_Printer.cutPaper(50);
							break;
						case 1:
							jPos_Printer.cutPaper(100);
							break;
						case 2:
							break;
						}
					}
				} catch (JposException e3) {
					// TODO Auto-generated catch block
					e3.printStackTrace();
				}

				try {
					jPos_Printer.transactionPrint(
							POSPrinterConst.PTR_S_RECEIPT,
							POSPrinterConst.PTR_TP_NORMAL);
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});

		jButton_LOGO.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				String ESC = ((char) 0x1b) + "";
				String sBuf = "";

				try {
					jPos_Printer.transactionPrint(
							POSPrinterConst.PTR_S_RECEIPT,
							POSPrinterConst.PTR_TP_TRANSACTION);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "RAM Logo:" + "\n");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|1B");
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"Can not print bitmap.", "Printer", 0);
				}

				try {
					byte pString[] = new byte[4];
					pString[0] = 0x1C;
					pString[1] = 0x70;
					pString[2] = 0x01;
					pString[3] = 0x00;

					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "Flash Logo:" + "\n");
					jPos_Printer.directIO(PRN_DI_OUTPUT_NORMAL, null, pString);
					sBuf = String.format("|%dlF", jPos_Printer
							.getRecLinesToPaperCut());
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ sBuf);

					if (jPos_Printer.getCapRecPapercut() == true) {
						switch (nCut) {
						case 0:
							jPos_Printer.cutPaper(50);
							break;
						case 1:
							jPos_Printer.cutPaper(100);
							break;
						case 2:
							break;
						}
					}

					jPos_Printer.transactionPrint(
							POSPrinterConst.PTR_S_RECEIPT,
							POSPrinterConst.PTR_TP_NORMAL);
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});

		jButton_Barcode.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				String ESC = ((char) 0x1b) + "";
				String sBuf = "";

				try {
					jPos_Printer.transactionPrint(
							POSPrinterConst.PTR_S_RECEIPT,
							POSPrinterConst.PTR_TP_TRANSACTION);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "UPC-A" + "\n");
					jPos_Printer.printBarCode(POSPrinterConst.PTR_S_RECEIPT,
							"01234567890", POSPrinterConst.PTR_BCS_UPCA, 1000,
							jPos_Printer.getRecLineWidth(),
							POSPrinterConst.PTR_BC_LEFT,
							POSPrinterConst.PTR_BC_TEXT_BELOW);
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"Can not print barcode UPC-A.", "Printer", 0);
				}

				try {
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|500uF");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "UPC-E" + "\n");
					jPos_Printer.printBarCode(POSPrinterConst.PTR_S_RECEIPT,
							"01234567890", POSPrinterConst.PTR_BCS_UPCE, 1000,
							jPos_Printer.getRecLineWidth(),
							POSPrinterConst.PTR_BC_LEFT,
							POSPrinterConst.PTR_BC_TEXT_BELOW);
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"Can not print barcode UPC-E.", "Printer", 0);
				}

				try {
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|500uF");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "EAN-13" + "\n");
					jPos_Printer.printBarCode(POSPrinterConst.PTR_S_RECEIPT,
							"012345678901", POSPrinterConst.PTR_BCS_EAN13,
							1000, jPos_Printer.getRecLineWidth(),
							POSPrinterConst.PTR_BC_LEFT,
							POSPrinterConst.PTR_BC_TEXT_BELOW);
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"Can not print barcode EAN-13.", "Printer", 0);
				}

				try {
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|500uF");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "EAN-8" + "\n");
					jPos_Printer.printBarCode(POSPrinterConst.PTR_S_RECEIPT,
							"0123456", POSPrinterConst.PTR_BCS_EAN8, 1000,
							jPos_Printer.getRecLineWidth(),
							POSPrinterConst.PTR_BC_LEFT,
							POSPrinterConst.PTR_BC_TEXT_BELOW);
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"Can not print barcode EAN-8.", "Printer", 0);
				}

				try {
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|500uF");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "CODE39" + "\n");
					jPos_Printer.printBarCode(POSPrinterConst.PTR_S_RECEIPT,
							"01234567", POSPrinterConst.PTR_BCS_Code39, 1000,
							jPos_Printer.getRecLineWidth(),
							POSPrinterConst.PTR_BC_LEFT,
							POSPrinterConst.PTR_BC_TEXT_BELOW);
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"Can not print barcode Code39.", "Printer", 0);
				}

				try {
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|500uF");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "ITF" + "\n");
					jPos_Printer.printBarCode(POSPrinterConst.PTR_S_RECEIPT,
							"01234567890", POSPrinterConst.PTR_BCS_ITF, 1000,
							jPos_Printer.getRecLineWidth(),
							POSPrinterConst.PTR_BC_LEFT,
							POSPrinterConst.PTR_BC_TEXT_NONE);
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"Can not print barcode ITF.", "Printer", 0);
				}

				try {
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|500uF");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "CODABAR" + "\n");
					jPos_Printer.printBarCode(POSPrinterConst.PTR_S_RECEIPT,
							"B1234567890B", POSPrinterConst.PTR_BCS_Codabar,
							1000, jPos_Printer.getRecLineWidth(),
							POSPrinterConst.PTR_BC_LEFT,
							POSPrinterConst.PTR_BC_TEXT_BELOW);
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"Can not print barcode Codabar.", "Printer", 0);
				}

				try {
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|500uF");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "CODE93" + "\n");
					jPos_Printer.printBarCode(POSPrinterConst.PTR_S_RECEIPT,
							"0123456789", POSPrinterConst.PTR_BCS_Code93, 1000,
							jPos_Printer.getRecLineWidth(),
							POSPrinterConst.PTR_BC_LEFT,
							POSPrinterConst.PTR_BC_TEXT_BELOW);
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"Can not print barcode Code93.", "Printer", 0);
				}

				try {
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|500uF");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "CODE128" + "\n");
					jPos_Printer.printBarCode(POSPrinterConst.PTR_S_RECEIPT,
							"{A0123456789", POSPrinterConst.PTR_BCS_Code128,
							1000, jPos_Printer.getRecLineWidth(),
							POSPrinterConst.PTR_BC_LEFT,
							POSPrinterConst.PTR_BC_TEXT_BELOW);
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"Can not print barcode Code128.", "Printer", 0);
				}

				try {
					sBuf = String.format("|%dlF", jPos_Printer
							.getRecLinesToPaperCut());
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ sBuf);

					if (jPos_Printer.getCapRecPapercut() == true) {
						switch (nCut) {
						case 0:
							jPos_Printer.cutPaper(50);
							break;
						case 1:
							jPos_Printer.cutPaper(100);
							break;
						case 2:
							break;
						}
					}
					jPos_Printer.transactionPrint(
							POSPrinterConst.PTR_S_RECEIPT,
							POSPrinterConst.PTR_TP_NORMAL);

				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});

		jButton_CodePage.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				String ESC = ((char) 0x1b) + "";
				String sBuf = "";
				int codepageID = 0;
				int index = 3;

				byte pString[] = new byte[128 + 4];
				pString[0] = 0x1B;
				pString[1] = 0x74;
				pString[2] = (byte) codepageID;

				for (int i = 0x80; i <= 0xFF; i++) {
					pString[index] = (byte) i;
					index++;
				}
				pString[index] = 0x0A;
				index++;

				try {
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "PC437: " + "\n");
					jPos_Printer.directIO(PRN_DI_OUTPUT_NORMAL, new int[1],
							pString);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "\r\n");

					codepageID = 1;// CodePage ID, 0-255
					pString[2] = (byte) codepageID;
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "PC857: " + "\n");
					jPos_Printer.directIO(PRN_DI_OUTPUT_NORMAL, null, pString);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "\r\n");

					codepageID = 2;// CodePage ID, 0-255
					pString[2] = (byte) codepageID;
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "PC850: " + "\n");
					jPos_Printer.directIO(PRN_DI_OUTPUT_NORMAL, null, pString);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "\r\n");

					codepageID = 3;// CodePage ID, 0-255
					pString[2] = (byte) codepageID;
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "PC860: " + "\n");
					jPos_Printer.directIO(PRN_DI_OUTPUT_NORMAL, null, pString);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "\r\n");

					codepageID = 4;// CodePage ID, 0-255
					pString[2] = (byte) codepageID;
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "PC863: " + "\n");
					jPos_Printer.directIO(PRN_DI_OUTPUT_NORMAL, null, pString);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "\r\n");

					codepageID = 5;// CodePage ID, 0-255
					pString[2] = (byte) codepageID;
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "PC865: " + "\n");
					jPos_Printer.directIO(PRN_DI_OUTPUT_NORMAL, null, pString);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "\r\n");

					codepageID = 6;// CodePage ID, 0-255
					pString[2] = (byte) codepageID;
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "PC852: " + "\n");
					jPos_Printer.directIO(PRN_DI_OUTPUT_NORMAL, null, pString);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "\r\n");

					codepageID = 7;// CodePage ID, 0-255
					pString[2] = (byte) codepageID;
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "PC858: " + "\n");
					jPos_Printer.directIO(PRN_DI_OUTPUT_NORMAL, null, pString);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "\r\n");

					codepageID = 8;// CodePage ID, 0-255
					pString[2] = (byte) codepageID;
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "PC866: " + "\n");
					jPos_Printer.directIO(PRN_DI_OUTPUT_NORMAL, null, pString);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "\r\n");

					codepageID = 9;// CodePage ID, 0-255
					pString[2] = (byte) codepageID;
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "WPC1252: " + "\n");
					jPos_Printer.directIO(PRN_DI_OUTPUT_NORMAL, null, pString);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "\r\n");

					codepageID = 38;// CodePage ID, 0-255
					pString[2] = (byte) codepageID;
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "PC1257:" + "\n");
					jPos_Printer.directIO(PRN_DI_OUTPUT_NORMAL, null, pString);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + "\r\n");

					sBuf = String.format("|%dlF", jPos_Printer
							.getRecLinesToPaperCut());
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ sBuf);

					if (jPos_Printer.getCapRecPapercut() == true) {
						switch (nCut) {
						case 0:
							jPos_Printer.cutPaper(50);
							break;
						case 1:
							jPos_Printer.cutPaper(100);
							break;
						case 2:
							break;
						}
					}
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});

		jButton_Merchant.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				class Goods {
					double[] Price = new double[4];
					String[] Name = new String[4];
				}

				Goods fGoods = new Goods();
				fGoods.Name[0] = "semi-conductor";
				fGoods.Price[0] = 6.98;
				fGoods.Name[1] = "energy-saving lighting";
				fGoods.Price[1] = 2.47;
				fGoods.Name[2] = "Thermal transfer Printer";
				fGoods.Price[2] = 67.95;
				fGoods.Name[3] = "program-controlled exchanger";
				fGoods.Price[3] = 128.23;

				String fDate = "";
				String ESC = ((char) 0x1b) + "";
				String sTmp, sPrice, sSpace;
				double Subtotal = 0.0;
				double Tax = 0.0;
				double Total = 0.0;
				double Payment = 0.0;
				double Change = 0.0;

				Calendar cal = Calendar.getInstance();
				java.text.SimpleDateFormat sdf = new SimpleDateFormat(
						"yyyy-MM-dd HH:mm:ss");
				fDate = sdf.format(cal.getTime());

				try {
					jPos_Printer.transactionPrint(
							POSPrinterConst.PTR_S_RECEIPT,
							POSPrinterConst.PTR_TP_TRANSACTION);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + fDate + "\n");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|rA" + "TEL 9999-99-9999   C#2\n");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|500uF");

					for (int i = 0; i < 4; i++) {
						Subtotal += fGoods.Price[i];
						sPrice = String.format("$%.2f", fGoods.Price[i]);
						int iLenth = jPos_Printer.getRecLineChars()
								- (fGoods.Name[i].length() + sPrice.length());
						sSpace = sPace(iLenth);
						jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
								fGoods.Name[i] + sSpace + sPrice + "\n");
					}

					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|500uF");
					sTmp = "Subtotal";
					sPrice = String.format("$%.2f", Subtotal);
					int iLenth = jPos_Printer.getRecLineChars()
							- (sTmp.length() + sPrice.length());
					sSpace = sPace(iLenth);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							sTmp + sSpace + sPrice + "\n");

					sTmp = "Tax";
					Tax = 12.33;
					sPrice = String.format("$%.2f", Tax);
					iLenth = jPos_Printer.getRecLineChars()
							- (sTmp.length() + sPrice.length());
					sSpace = sPace(iLenth);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							sTmp + sSpace + sPrice + "\n");

					sTmp = "Total";
					Total = Subtotal + Tax;
					sPrice = String.format("$%.2f", Total);
					iLenth = jPos_Printer.getRecLineChars()
							- (sTmp.length() + sPrice.length());
					sSpace = sPace(iLenth);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|bC" + ESC + "|uC" + sTmp + sSpace + sPrice
							+ "\n");

					sTmp = "Payment";
					Payment = 220.00;
					sPrice = String.format("$%.2f", Payment);
					iLenth = jPos_Printer.getRecLineChars()
							- (sTmp.length() + sPrice.length());
					sSpace = sPace(iLenth);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							sTmp + sSpace + sPrice + "\n");

					sTmp = "Change";
					Change = Payment - Total;
					sPrice = String.format("$%.2f", Change);
					iLenth = jPos_Printer.getRecLineChars()
							- (sTmp.length() + sPrice.length());
					sSpace = sPace(iLenth);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							sTmp + sSpace + sPrice + "\n");

					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|800uF");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|cA" + ESC + "|2C" + "** Merchant Copy **"
							+ "\n");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|500uF");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|cA" + ESC + "|2C" + "_ _ _ _ _ _ _ _ _ _\n");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|cA" + "customer signature");
					sTmp = String.format("|%dlF", jPos_Printer
							.getRecLinesToPaperCut());
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ sTmp);

					if (jPos_Printer.getCapRecPapercut() == true) {
						switch (nCut) {
						case 0:
							jPos_Printer.cutPaper(50);
							break;
						case 1:
							jPos_Printer.cutPaper(100);
							break;
						case 2:
							break;
						}
					}
					jPos_Printer.transactionPrint(
							POSPrinterConst.PTR_S_RECEIPT,
							POSPrinterConst.PTR_TP_NORMAL);
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});

		jButton_Customer.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				class Goods {
					double[] Price = new double[4];
					String[] Name = new String[4];
				}

				Goods fGoods = new Goods();
				fGoods.Name[0] = "semi-conductor";
				fGoods.Price[0] = 6.98;
				fGoods.Name[1] = "energy-saving lighting";
				fGoods.Price[1] = 2.47;
				fGoods.Name[2] = "Thermal transfer Printer";
				fGoods.Price[2] = 67.95;
				fGoods.Name[3] = "program-controlled exchanger";
				fGoods.Price[3] = 128.23;

				String fDate;
				String ESC = ((char) 0x1b) + "";
				String sTmp, sPrice, sSpace;
				String Code128 = "{A12{S{S{CAB{BAB";
				double Subtotal = 0.0;
				double Tax = 0.0;
				double Total = 0.0;
				double Payment = 0.0;
				double Change = 0.0;

				Calendar cal = Calendar.getInstance();
				java.text.SimpleDateFormat sdf = new SimpleDateFormat(
						"yyyy-MM-dd HH:mm:ss");
				fDate = sdf.format(cal.getTime());

				try {
					jPos_Printer.transactionPrint(
							POSPrinterConst.PTR_S_RECEIPT,
							POSPrinterConst.PTR_TP_TRANSACTION);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|N" + fDate + "\n");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|rA" + "TEL 9999-99-9999   C#2\n");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|500uF");

					for (int i = 0; i < 4; i++) {
						Subtotal += fGoods.Price[i];
						sPrice = String.format("$%.2f", fGoods.Price[i]);
						int iLenth = jPos_Printer.getRecLineChars()
								- (fGoods.Name[i].length() + sPrice.length());
						sSpace = sPace(iLenth);
						jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
								fGoods.Name[i] + sSpace + sPrice + "\n");
					}

					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|500uF");
					sTmp = "Subtotal";
					sPrice = String.format("$%.2f", Subtotal);
					int iLenth = jPos_Printer.getRecLineChars()
							- (sTmp.length() + sPrice.length());
					sSpace = sPace(iLenth);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							sTmp + sSpace + sPrice + "\n");

					sTmp = "Tax";
					Tax = 12.33;
					sPrice = String.format("$%.2f", Tax);
					iLenth = jPos_Printer.getRecLineChars()
							- (sTmp.length() + sPrice.length());
					sSpace = sPace(iLenth);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							sTmp + sSpace + sPrice + "\n");

					sTmp = "Total";
					Total = Subtotal + Tax;
					sPrice = String.format("$%.2f", Total);
					iLenth = jPos_Printer.getRecLineChars()
							- (sTmp.length() + sPrice.length());
					sSpace = sPace(iLenth);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|bC" + ESC + "|uC" + sTmp + sSpace + sPrice
							+ "\n");

					sTmp = "Payment";
					Payment = 220.00;
					sPrice = String.format("$%.2f", Payment);
					iLenth = jPos_Printer.getRecLineChars()
							- (sTmp.length() + sPrice.length());
					sSpace = sPace(iLenth);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							sTmp + sSpace + sPrice + "\n");

					sTmp = "Change";
					Change = Payment - Total;
					sPrice = String.format("$%.2f", Change);
					iLenth = jPos_Printer.getRecLineChars()
							- (sTmp.length() + sPrice.length());
					sSpace = sPace(iLenth);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							sTmp + sSpace + sPrice + "\n");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|800uF");

					jPos_Printer.printBarCode(POSPrinterConst.PTR_S_RECEIPT,
							Code128, POSPrinterConst.PTR_BCS_Code128, 1000,
							jPos_Printer.getRecLineWidth(),
							POSPrinterConst.PTR_BC_CENTER,
							POSPrinterConst.PTR_BC_TEXT_BELOW);
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"Can not print barcode.", "Printer", 0);
				}
				try {
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|500uF");
					sTmp = "**   Thank you   **";
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|cA" + ESC + "|2C" + sTmp + "\n");
					sTmp = " Customer Copy ";
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|cA" + ESC + "|2C" + "**    " + ESC + "|1C"
							+ sTmp + ESC + "|2C" + "    **" + "\n");
					sTmp = "Save Receipt for Returns";
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|cA" + ESC + "|2C" + "**   " + ESC + "|1C"
							+ sTmp + "   **" + "\n");
					sTmp = String.format("|%dlF", jPos_Printer
							.getRecLinesToPaperCut());
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ sTmp);

					if (jPos_Printer.getCapRecPapercut() == true) {
						switch (nCut) {
						case 0:
							jPos_Printer.cutPaper(50);
							break;
						case 1:
							jPos_Printer.cutPaper(100);
							break;
						case 2:
							break;
						}
					}
					jPos_Printer.transactionPrint(
							POSPrinterConst.PTR_S_RECEIPT,
							POSPrinterConst.PTR_TP_NORMAL);
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});

		jButton_PrintReceipt.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				boolean bExit;
				String ESC = ((char) 0x1b) + "";
				String fDate;
				String sBuf;
				String BcData;

				try {
					if (jPos_Printer.getCapRecPresent() == false) {
						JOptionPane
								.showMessageDialog(
										null,
										"This Printer doesn't have the Receipt Station.",
										"Printer", 0);
						return;
					}

					if (jPos_Printer.getCapRecLeft90() == false) {
						JOptionPane
								.showMessageDialog(
										null,
										"This printer doesn't have a rotation printing function.",
										"Printer", 0);
						return;
					}

					Calendar cal = Calendar.getInstance();
					java.text.SimpleDateFormat sdf = new SimpleDateFormat(
							"yyyy-MM-dd");
					fDate = sdf.format(cal.getTime());
					bExit = false;
					BcData = "123456789012";

					jPos_Printer.setAsyncMode(true);
					jPos_Printer.transactionPrint(
							POSPrinterConst.PTR_S_RECEIPT,
							POSPrinterConst.PTR_TP_TRANSACTION);

				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					JOptionPane.showMessageDialog(null,
							"Can't use a POS Printer.", "Printer", 0);
					return;
				}

				try {
					jPos_Printer.rotatePrint(POSPrinterConst.PTR_S_RECEIPT,
							POSPrinterConst.PTR_RP_LEFT90
									+ POSPrinterConst.PTR_RP_BITMAP
									+ POSPrinterConst.PTR_RP_BARCODE);
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}

				while (true) {
					try {
						jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
								ESC + "|4C" + ESC + "|bC" + "Receipt\n");
						sBuf = sPace(29);
						jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
								ESC + "|2uC" + sBuf + fDate + "\n");

						jPos_Printer.setRecLineSpacing(jPos_Printer
								.getRecLineHeight());
						sBuf = sLine(45);
						jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
								"No.             Receiver             Time\n");

						Calendar cal = Calendar.getInstance();
						java.text.SimpleDateFormat sdf = new SimpleDateFormat(
								"HH:mm:ss");
						fDate = sdf.format(cal.getTime());

						jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
								"0013            0031                 " + fDate
										+ "\n");
						jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
								ESC + "|N" + sBuf + "\n");
						jPos_Printer
								.printNormal(POSPrinterConst.PTR_S_RECEIPT,
										"Dairy(020217)                          $28.00\n");
						jPos_Printer
								.printNormal(POSPrinterConst.PTR_S_RECEIPT,
										"Frozen(020219)                         $12.00\n");
						jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
								ESC + "|N" + sBuf + "\n");
						sBuf = "Subtotal                               $40.00";
						jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
								sBuf + "\n");
						sBuf = "Sales Tax                               $1.80";
						jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
								sBuf + "\n");
						sBuf = "Total                                  $41.80";
						jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
								ESC + "|bC" + sBuf + "\n");
						sBuf = "Payment                                $50.00";
						jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
								sBuf + "\n");
						sBuf = "Change                                  $8.20";
						jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
								sBuf + "\n");
						sBuf = sLine(45);
						jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
								ESC + "|N" + sBuf + "\n");
						jPos_Printer.printBarCode(
								POSPrinterConst.PTR_S_RECEIPT, BcData,
								POSPrinterConst.PTR_BCS_UPCA, 500, jPos_Printer
										.getRecLineWidth() / 2,
								POSPrinterConst.PTR_BC_CENTER,
								POSPrinterConst.PTR_BC_TEXT_BELOW);
						break;

					} catch (JposException e1) {
						e1.printStackTrace();
						Object[] options = { "Stop", "Retry", "Ignore" };
						int n = JOptionPane.showOptionDialog(null,
								"Fails to output to a printer.\nRetry?",
								"Warning ", JOptionPane.DEFAULT_OPTION,
								JOptionPane.WARNING_MESSAGE, null, options,
								options[0]);
						if (n != 2) {
							try {
								jPos_Printer.clearOutput();
							} catch (JposException e2) {
								// TODO Auto-generated catch block
								e2.printStackTrace();
							}
						}
						if (n == 0) {
							bExit = true;
							return;
						}
						if (n != 1) {
							break;
						}
					}
				}

				try {
					jPos_Printer.rotatePrint(POSPrinterConst.PTR_S_RECEIPT,
							POSPrinterConst.PTR_RP_NORMAL);
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}

				if (!bExit) {
					try {
						sBuf = String.format("|%dlF", jPos_Printer
								.getRecLinesToPaperCut());
						jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
								ESC + sBuf);
					} catch (JposException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				} else {
					try {
						jPos_Printer.clearOutput();
					} catch (JposException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				}

				while (jPos_Printer.getState() != 2)
					;
				try {
					jPos_Printer.transactionPrint(
							POSPrinterConst.PTR_S_RECEIPT,
							POSPrinterConst.PTR_TP_NORMAL);
					jPos_Printer.setAsyncMode(false);
					if (jPos_Printer.getCapRecPapercut() == true) {
						switch (nCut) {
						case 0:
							jPos_Printer.cutPaper(50);
							break;
						case 1:
							jPos_Printer.cutPaper(100);
							break;
						case 2:
							break;
						}
					}
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});

		jButton_ATMReceipt.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				class ATMITEM {
					String[] Item = new String[3];
					String[] Count = new String[3];
				}

				ATMITEM fAtm = new ATMITEM();
				String sTmp, fDate;
				String ESC = ((char) 0x1b) + "";
				int iLenth;

				fAtm.Item[0] = "ACCOUNT NO.";
				fAtm.Count[0] = "0123456000";
				fAtm.Item[1] = "CURRENT BALANCE";
				fAtm.Count[1] = "$100000";
				fAtm.Item[2] = "CHANGE";
				fAtm.Count[2] = "$10000";

				Calendar cal = Calendar.getInstance();
				java.text.SimpleDateFormat sdf = new SimpleDateFormat(
						"yyyy-MM-dd HH:mm:ss");
				fDate = sdf.format(cal.getTime());

				try {
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|cA" + fDate + "\n");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|500uF");
					for (int i = 0; i < 3; i++) {
						iLenth = jPos_Printer.getRecLineChars()
								- (fAtm.Item[i].length() + fAtm.Count[i]
										.length());
						sTmp = sPace(iLenth);
						jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
								fAtm.Item[i] + sTmp + fAtm.Count[i] + "\n");
						jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
								ESC + "|200uF");
					}
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|300uF");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|cA" + "Happy Christmas!" + '\n');
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ "|cA" + "HAVE A NICE DAY" + '\n');
					sTmp = String.format("|%dlF", jPos_Printer
							.getRecLinesToPaperCut());
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ sTmp);

					if (jPos_Printer.getCapRecPapercut() == true) {
						switch (nCut) {
						case 0:
							jPos_Printer.cutPaper(50);
							break;
						case 1:
							jPos_Printer.cutPaper(100);
							break;
						case 2:
							break;
						}
					}
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});

		jButton_AccountSumm.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				String ESC = ((char) 0x1b) + "";
				String fDate;
				String sBuf1, sBuf2, sBuf3, sBuf4, sBuf5;

				Calendar cal = Calendar.getInstance();
				java.text.SimpleDateFormat sdf = new SimpleDateFormat(
						"yyyy-MM-dd HH:mm:ss");
				fDate = sdf.format(cal.getTime());

				try {
					jPos_Printer.setAsyncMode(false);
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}

				try {
					jPos_Printer.rotatePrint(POSPrinterConst.PTR_S_RECEIPT,
							POSPrinterConst.PTR_RP_RIGHT90);
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
					JOptionPane
							.showMessageDialog(
									null,
									"This printer doesn't have a rotation printing function.",
									"Printer", 0);
				}

				sBuf1 = "ACCOUNT MUMBER:";
				sBuf2 = "038261151100";
				sBuf3 = sPace(5);
				int iLenth = sBuf1.length() + 5 - sBuf2.length();
				sBuf4 = sPace(iLenth);
				try {
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							sBuf1 + sBuf3 + sBuf2 + sBuf4 + fDate + "\n");

					sBuf1 = "ACCOUNT TITLE:";
					sBuf2 = "CHECKING ACCOUNT";
					sBuf3 = sPace(6);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							sBuf1 + sBuf3 + sBuf2 + "\n");

					sBuf1 = "CARD NUMBER:";
					sBuf2 = "12345678901234567890";
					sBuf3 = sPace(8);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							sBuf1 + sBuf3 + sBuf2 + "\n");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							"\n");

					sBuf1 = "MR.and MS.ANGELO DUNDEE";
					sBuf2 = sLine(25);
					sBuf3 = sPace(15);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							sBuf1 + sBuf3 + sBuf2 + "\n");

					sBuf1 = "5298 KINGSWAY COURT WEST APT 2";
					sBuf2 = "ASK FOR INFORMATION ABOUT";
					sBuf3 = sPace(8);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							sBuf1 + sBuf3 + sBuf2 + "\n");

					sBuf1 = "TAYSIDE MEDOWS TOWNHOUSE";
					sBuf2 = "OUR LOW INTEREST RATE";
					sBuf3 = sPace(14);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							sBuf1 + sBuf3 + sBuf2 + "\n");

					sBuf1 = "ANYTOWN,  ANYSTATE  98765-4321";
					sBuf2 = "AUTOMOBILE LOANS!";
					sBuf3 = sPace(16);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							sBuf1 + sBuf3 + sBuf2 + "\n");

					sBuf1 = sPace(38);
					sBuf2 = sLine(25);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							sBuf1 + sBuf2 + "\n");
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							"\n");

					sBuf1 = "DATE           ";
					sBuf2 = "WITHDRAWALS  ";
					sBuf3 = "DEPOSITS    ";
					sBuf4 = "DESCRIPTION         ";
					sBuf5 = "BALANCE";
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							sBuf1 + sBuf2 + sBuf3 + sBuf4 + sBuf5 + "\n");

					// sdf = new SimpleDateFormat("yyyy-MM-dd");
					// fDate = sdf.format(cal.getTime());
					fDate = "3/19/1999";
					double payout = 30.0, deposit = 0.0, balance = 2666.50;
					if (payout == 0.0)
						sBuf1 = sPace(8);
					else
						sBuf1 = String.format("            %.2f", payout);
					if (deposit == 0.0)
						sBuf2 = sPace(14);
					else
						sBuf2 = String.format("    %.2f", deposit);

					sBuf3 = "ATM FAST CASH";
					sBuf4 = String.format("       %.2f", balance);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							fDate + sBuf1 + sBuf2 + sBuf3 + sBuf4 + "\n");

					fDate = "4/19/2000";
					payout = 30.0;
					deposit = 0.0;
					balance = balance - payout + deposit;
					if (payout == 0.0)
						sBuf1 = sPace(8);
					else
						sBuf1 = String.format("            %.2f", payout);
					if (deposit == 0.0)
						sBuf2 = sPace(14);
					else
						sBuf2 = String.format("    %.2f", deposit);

					sBuf3 = "ATM FAST CASH";
					sBuf4 = String.format("       %.2f", balance);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							fDate + sBuf1 + sBuf2 + sBuf3 + sBuf4 + "\n");

					fDate = "5/19/2000";
					payout = 110.0;
					deposit = 0.0;
					balance = balance - payout + deposit;
					if (payout == 0.0)
						sBuf1 = sPace(7);
					else
						sBuf1 = String.format("           %.2f", payout);
					if (deposit == 0.0)
						sBuf2 = sPace(14);
					else
						sBuf2 = String.format("    %.2f", deposit);
					sBuf3 = "ATM FAST CASH";
					sBuf4 = String.format("       %.2f", balance);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							fDate + sBuf1 + sBuf2 + sBuf3 + sBuf4 + "\n");

					fDate = "6/19/2000";
					payout = 0.0;
					deposit = 1152.34;
					balance = balance - payout + deposit;
					if (payout == 0.0)
						sBuf1 = sPace(20);
					else
						sBuf1 = String.format("     %.2f", payout);
					if (deposit == 0.0)
						sBuf2 = sPace(14);
					else
						sBuf2 = String.format("%.2f    ", deposit);
					sBuf3 = "ATM FAST CASH";
					sBuf4 = String.format("       %.2f", balance);
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							fDate + sBuf1 + sBuf2 + sBuf3 + sBuf4 + "\n");

					sBuf1 = sPace(20);
					sBuf2 = "----HAVE A NICE DAY!----";
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT,
							sBuf1 + sBuf2 + "\n");

					jPos_Printer.rotatePrint(POSPrinterConst.PTR_S_RECEIPT,
							POSPrinterConst.PTR_RP_NORMAL);
					sBuf1 = String.format("|%dlF", jPos_Printer
							.getRecLinesToPaperCut());
					jPos_Printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, ESC
							+ sBuf1);

					if (jPos_Printer.getCapRecPapercut() == true) {
						switch (nCut) {
						case 0:
							jPos_Printer.cutPaper(50);
							break;
						case 1:
							jPos_Printer.cutPaper(100);
							break;
						case 2:
							break;
						}
					}
					jPos_Printer.setAsyncMode(false);
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});

		jButton_DirectIOSample.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				String CRLF = "\r\n";

				byte pString[] = new byte[3];
				pString[0] = 0x1B;
				pString[1] = 0x61;
				pString[2] = 0x01;

				try {
					jPos_Printer.directIO(100, null, pString);
					String strBuffer = "DirectIO Test" + CRLF;
					jPos_Printer.directIO(100, null, strBuffer.getBytes());
				} catch (JposException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});

		jButton_SamplePrint.setText("Sample Print");
		jButton_LOGO.setText("LOGO");
		jButton_Barcode.setText("Barcode");
		jButton_CodePage.setText("CodePage");
		jButton_Merchant.setText("Merchant");
		jButton_Customer.setText("Customer");
		jButton_PrintReceipt.setText("Print Receipt");
		jButton_ATMReceipt.setText("ATM Receipt");
		jButton_AccountSumm.setText("Account Summ");
		jButton_DirectIOSample.setText("DirectIO Sample");

		jPanel_Frame.add(jButton_SamplePrint);
		jPanel_Frame.add(jButton_LOGO);
		jPanel_Frame.add(jButton_Barcode);
		jPanel_Frame.add(jButton_CodePage);
		jPanel_Frame.add(jButton_Merchant);
		jPanel_Frame.add(jButton_Customer);
		jPanel_Frame.add(jButton_PrintReceipt);
		jPanel_Frame.add(jButton_ATMReceipt);
		jPanel_Frame.add(jButton_AccountSumm);
		jPanel_Frame.add(jButton_DirectIOSample);
		jPanel_Frame.add(jRadioBTN_PartCut);
		jPanel_Frame.add(jRadioBTN_FullCut);
		jPanel_Frame.add(jRadioBTN_NoCut);
		jPanel_Frame.add(jPanel_ReceiptRetail);
		jPanel_Frame.add(jPanel_ReceiptBanking);
		jPanel_Frame.add(jPanel_CutMode);

		jPanel_Frame.setLayout(null);

		int iLeftBase = 30;
		int iTopBase = 40;
		int iWidthBase = 110;
		int iHeightBase = 30;
		jButton_SamplePrint.setBounds(iLeftBase, iTopBase, iWidthBase,
				iHeightBase);
		jButton_LOGO.setBounds(iLeftBase, iTopBase + 40, iWidthBase,
				iHeightBase);
		jButton_Barcode.setBounds(iLeftBase, iTopBase + 80, iWidthBase,
				iHeightBase);
		jButton_CodePage.setBounds(iLeftBase, iTopBase + 120, iWidthBase,
				iHeightBase);
		jButton_Merchant.setBounds(iLeftBase, iTopBase + 160, iWidthBase,
				iHeightBase);
		jButton_Customer.setBounds(iLeftBase, iTopBase + 200, iWidthBase,
				iHeightBase);
		jButton_PrintReceipt.setBounds(iLeftBase, iTopBase + 240, iWidthBase,
				iHeightBase);
		jButton_ATMReceipt.setBounds(iLeftBase + 150, iTopBase, iWidthBase,
				iHeightBase);
		jButton_AccountSumm.setBounds(iLeftBase + 150, iTopBase + 40,
				iWidthBase, iHeightBase);
		jButton_DirectIOSample.setBounds(iLeftBase + 150, iTopBase + 240,
				iWidthBase, iHeightBase);

		jPanel_ReceiptRetail.setBounds(iLeftBase - 15, iTopBase - 25,
				iWidthBase + 30, iHeightBase + 280);
		jPanel_ReceiptBanking.setBounds(iLeftBase + 135, iTopBase - 25,
				iWidthBase + 30, iHeightBase + 80);
		jPanel_CutMode.setBounds(iLeftBase + 135, iTopBase + 90,
				iWidthBase + 30, iHeightBase + 80);

		jRadioBTN_PartCut.setBounds(iLeftBase + 150, iTopBase + 105,
				iWidthBase, iHeightBase);
		jRadioBTN_FullCut.setBounds(iLeftBase + 150, iTopBase + 130,
				iWidthBase, iHeightBase);
		jRadioBTN_NoCut.setBounds(iLeftBase + 150, iTopBase + 155, iWidthBase,
				iHeightBase);
		jPanel_Frame.validate();

		jButton_SamplePrint.setMargin(Insets_Button);
		jButton_LOGO.setMargin(Insets_Button);
		jButton_Barcode.setMargin(Insets_Button);
		jButton_CodePage.setMargin(Insets_Button);
		jButton_Merchant.setMargin(Insets_Button);
		jButton_Customer.setMargin(Insets_Button);
		jButton_PrintReceipt.setMargin(Insets_Button);
		jButton_ATMReceipt.setMargin(Insets_Button);
		jButton_AccountSumm.setMargin(Insets_Button);
		jButton_DirectIOSample.setMargin(Insets_Button);

		pack();
	}

	private void InitDialog() {
		boolean bError = false;

		while (true) {
			try {
				jPos_Printer.open("byprn");
			} catch (JposException e) {
				e.printStackTrace();
				JOptionPane.showMessageDialog(null,
						"This device has not been registered, or can't use.",
						"Printer", 0);
				bError = true;
				break;
			}

			try {
				jPos_Printer.claim(1000);
			} catch (JposException e) {
				e.printStackTrace();
				JOptionPane.showMessageDialog(null,
						"Fails to get the exclusive right for the device.",
						"Printer", 0);
				bError = true;
				break;
			}

			try {
				jPos_Printer.setDeviceEnabled(true);
			} catch (JposException e) {
				e.printStackTrace();
				JOptionPane.showMessageDialog(null,
						"Now the device is disabled to use.", "Printer", 0);
				bError = true;
				break;
			}

			try {
				jPos_Printer.setMapMode(POSPrinterConst.PTR_MM_METRIC);
			} catch (JposException e) {
				e.printStackTrace();
			}

			try {
				int iRecLineWidth = jPos_Printer.getRecLineWidth();
				jPos_Printer.setBitmap(1, POSPrinterConst.PTR_S_RECEIPT,
						"bmp\\Lion.bmp", iRecLineWidth / 3,
						POSPrinterConst.PTR_BM_CENTER);
			} catch (JposException e) {
				e.printStackTrace();
				JOptionPane.showMessageDialog(null,
						"Can not find the specific bitmap", "Printer", 0);
			}
			break;
		}

		if (bError == true) {
			jButton_SamplePrint.setEnabled(false);
			jButton_LOGO.setEnabled(false);
			jButton_Barcode.setEnabled(false);
			jButton_CodePage.setEnabled(false);
			jButton_Merchant.setEnabled(false);
			jButton_Customer.setEnabled(false);
			jButton_PrintReceipt.setEnabled(false);
			jButton_ATMReceipt.setEnabled(false);
			jButton_AccountSumm.setEnabled(false);
			jButton_DirectIOSample.setEnabled(false);
			jRadioBTN_PartCut.setEnabled(false);
			jRadioBTN_FullCut.setEnabled(false);
			jRadioBTN_NoCut.setEnabled(false);

			return;
		} else {
			jRadioBTN_PartCut.setSelected(true);
		}
		nCut = 0;
	}

	public Printer() {
		InitFram();
		InitDialog();
	}
}
